package com.jqr.activity.school.http;
import androidx.annotation.NonNull;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitHelper {
    public static  JqrService getJqrService(){
        OkHttpClient.Builder httpClient=new OkHttpClient.Builder();
        //拦截器
        httpClient.addInterceptor(new Interceptor() {
            @NonNull
            @Override
            public Response intercept(@NonNull Chain chain) throws IOException {

                Request original= chain.request();
                Request request=original.newBuilder()
                        //为所用请求添加Header值
                        .header("Content-Type","application/json;charset=UTF-8")
                        .header("token","eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3MjMwODMwNTgsInN1YiI6ImFkbWluMTIzNDUiLCJpYXQiOjE3MjA0OTEwNTg1Nzh9.9Hd0Qttay4y-eOETSzGJXpQkBRU6tGyzxnI_LosTDLmF9APPniRVeKXfo5ekZuRGoYqhFv5DPJj7upf5iL3F3A")
                       // .method(original.method(),original.body())
                        .build();

                return chain.proceed(request);
            }
        });


        Retrofit retrofit=new Retrofit.Builder()
//                    .baseUrl("http://api.jqrjq.cn/")
                .baseUrl("http://10.0.2.2:8080/")
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient.build())
                .build();
        return retrofit.create(JqrService.class);
    }
}
